package com.ttedu.base;


import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * @功能：公共的BaseAction
 * 
 * @作者： fenglei
 * @作成时间：2012-06-22 上午11:09:24
 * 
 * @修改者：
 * @修改内容：
 * @修改时间：
 * 
 */
public class BaseAction extends ActionSupport implements ServletRequestAware {

	protected HttpServletRequest request;
	protected HttpServletResponse response;
	protected HttpSession session;
	protected ServletContext application;

	/**
	 * 
	 * @功能：判断当前方法是否为get方法
	 * 
	 * @作者： fenglei
	 * @作成时间：2012-06-22 上午11:09:24
	 * 
	 * @修改者：
	 * @修改内容：
	 * @修改时间：
	 * 
	 * @return
	 */
	public boolean isGetRequest() {
		return request.getMethod().equalsIgnoreCase("get");
	}

	/**
	 * 实现org.apache.struts2.interceptor.ServletRequestAware接口，
	 * 重写setServletRequest()方法 ,获取HttpServletRequest对象，
	 * 再通过HttpServletRequest对象取昨HttpSession和ServletContext对象
	 * 
	 * @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
	 */
	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		this.request = arg0;
		this.session = arg0.getSession();
		this.application = session.getServletContext();
		this.response = ServletActionContext.getResponse();
	}
}
